/**
 * 
 */
package com.cchr.acms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cchr.acms.dao.UserDAO;
import com.cchr.acms.dao.UserPasswordDAO;
import com.cchr.acms.model.User;
import com.cchr.acms.model.UserPassword;
import com.cchr.acms.service.UserService;

/**
 * @author Zeng
 *
 */
@Service
public class UserServiceImpl implements UserService{
 
    @Autowired
    private UserDAO userDAO;
    @Autowired
    private UserPasswordDAO userPasswordDAO;
     
    public int insertUser(User user) {
        return userDAO.insertUser(user);
    }
    
    public int updateUser(User user){
    	return userDAO.updateUser(user);
    }
    
    public int deleteUser(int id){
    	return userDAO.deleteUser(id);
    }
    
    public User getUserById(int id){
    	return userDAO.getUserById(id);
    }
    
    public User getUserByUserName(String userName){
    	return userDAO.getUserByUserName(userName);
    }
    
    public User getUserByEmail(String email){
    	return userDAO.getUserByEmail(email);
    }

	public List<User> getAllUser() {
		return userDAO.getAllUser();
	}

	public List<User> queryUser(User user, int recordIndex, int pageNum) {
		Map paramMap=new HashMap();
//		paramMap.put("p_first_name", user.getFirstName());
//		paramMap.put("p_middle_name", user.getMiddleName());
//		paramMap.put("p_last_name", user.getLastName());
		paramMap.put("p_userName", user.getUserName());
		paramMap.put("p_email", user.getEmail());
		paramMap.put("recordIndex", recordIndex);
		paramMap.put("pageNum", pageNum);
		return userDAO.queryUser(paramMap);
	}

	public int queryUserCount(User user) {
		Map paramMap=new HashMap();
//		paramMap.put("p_first_name", user.getFirstName());
//		paramMap.put("p_middle_name", user.getMiddleName());
//		paramMap.put("p_last_name", user.getLastName());
		paramMap.put("p_userName", user.getUserName());
		paramMap.put("p_email", user.getEmail());
		return userDAO.queryUserCount(paramMap);
	}
	
	public int insertUserPassword(UserPassword userPassword) {
		return userPasswordDAO.insertUserPassword(userPassword);
    }
    public int updateUser(UserPassword userPassword){
    	return userPasswordDAO.updateUserPassword(userPassword);
    }
    public UserPassword getUserPasswordByUserName(String userName){
    	return userPasswordDAO.getUserPasswordByUserName(userName);
    }
    
    public void deleteUserPasswordByUserName(String userName){
    	userPasswordDAO.deleteUserPasswordByUserName(userName);
    }
    
    public String getCrypedSid(String seed){
    	return userPasswordDAO.getCrypedSid(seed);
    }
}
